﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using sohn.regextended;

namespace sohn.TestRegex
{
    public class OpenSimConfigLine
    {

        public override string ToString()
        {
            return "Option=>" + Option + " DependsOn=>" +
                DependsOn + " Question=>" + Question +
                " Choices=> " + Choices + " Default=>" + Default;
        }

        public string Option { get; set; }
        public string DependsOn { get; set; }
        public string Question { get; set; }
        public string Choices { get; set; }
        public string Default { get; set; }

        static RegBase noendchar = RegBase.Start().NoCharacterMatches("}").ZeroOrMore();

        static RegBase configOptions
		= RegBase.Start().Whitespace().ZeroOrMore().Literal(";#").Whitespace().OneOrMore().
		   Literal("{").StringExtract(noendchar).Literal("}").
          Whitespace().OneOrMore().Literal("{").
		   StringExtract(noendchar).
          Literal("}").
          Whitespace().OneOrMore().
		   Literal("{").StringExtract(noendchar).
          Literal("}").
          Whitespace().OneOrMore().
		   Literal("{").StringExtract(noendchar).
          Literal("}").
          Whitespace().OneOrMore().
		  StringExtract(RegBase.Start().NoCharacterMatches(";").ZeroOrMore());

        public static List<OpenSimConfigLine> GetLines(string filename)
        {

            string test = configOptions.GetFullPattern;
            List<OpenSimConfigLine> results = new List<OpenSimConfigLine>();

            System.IO.StreamReader sr = new System.IO.StreamReader(filename);

			string src = sr.ReadToEnd ();

			RegResult matchTree = configOptions.MatchTree (src, null);

			RegExtractor r = new RegExtractor (matchTree);

            sr.Close();

            return results;
        }
    }
}
